package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"short_video/api/request"
	"short_video/internal/dao"
	"short_video/internal/model"
)

func AddVideo(c *gin.Context) {
	var req request.AddVideo

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "参数信息失败",
			"data": err.Error(),
		})
		return
	}
	userId := c.GetUint("userId")
	var user model.User
	dao.GetOneById(userId, &user)

	dao.Create(&model.Video{
		Title:   req.Title,
		Info:    req.Info,
		FileUrl: req.FileUrl,
		UserId:  userId,
	})
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "短视频发布成功",
		"data": true,
	})

}
